package com.training1.core.web.controller;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.training1.core.common.controller.BaseController;
import com.training1.core.dto.AccountSystemParamDto;
import com.training1.core.modules.service.SystemSettingsService;
@Controller
@RequestMapping("accountsetting")
public class AccountSettingController extends BaseController {
	@Resource
	private SystemSettingsService accountService;
	
	@RequestMapping("setting")
	public String setting(Model model){
		AccountSystemParamDto dto = accountService.findAccountAllList();
		model.addAttribute("accountSystemParamForm", dto);
		model.addAttribute("successInfo", "");
		return "system/accountSetting";
	}

	
	
	/**
	 * @param settingparam
	 * @param result 
	 * @return
	 */
	@RequestMapping(value="save", method={RequestMethod.POST})
	public String save(@Valid @ModelAttribute("accountSystemParamForm") AccountSystemParamDto accountSystemParamForm,
			BindingResult result, Model model){
		if(result.hasErrors()){
			return "system/accountSetting";
		}
		
		String  message = accountService.saveaccountSettings(accountSystemParamForm);
		model.addAttribute("accountSystemParamForm", accountSystemParamForm);
		model.addAttribute("successInfo",message);
		return "system/accountSetting";
	}
	
	
	
//	@RequestMapping(value="getsetting", method={RequestMethod.POST})
//	@ResponseBody
//	public RespJson getsetting(Model mode, BindingResult result ){
//		if(result.hasErrors()){
//			return RespJsonFactory.buildFailure(result.getAllErrors().get(0).getDefaultMessage(), "module.user.save.error");
//		}
//		AccountSystemParamDto dto = accountService.findAccountAllList();	
//		return RespJsonFactory.buildSuccess(dto);
//	}
	
	
}
